package epidemic

import (
	"gitee.com/baal1990/epidemic/global"
	response "gitee.com/baal1990/epidemic/model/common/response_dfitc"
	epidemicReq "gitee.com/baal1990/epidemic/model/epidemic/request"
	epidemic2 "gitee.com/baal1990/epidemic/service/epidemic"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type DataStatisticsApi struct {
}

// GetDataStatistics 获取统计数据
func (ds *DataStatisticsApi) GetDataStatistics(c *gin.Context) {
	// 权限校验
	// epidemicUser := c.MustGet("OPERATION_USER_INFO").(epidemic.EpidemicUser)
	// if epidemicUser.Role != global.DICT_ROLES_SUPER {
	// 	response.FailWithMessage("账号权限不足", c)
	// 	return
	// }
	id := c.Param("id")
	global.GVA_LOG.Info("请求参数", zap.Any("param", id))
	service := epidemic2.DataStatistics{}
	switch id {
	case global.DATA_STATISTICS_USER_INPOSITION:
		req := epidemicReq.EpidemicUserSearch{}
		if err := c.ShouldBindQuery(&req); err != nil {
			global.GVA_LOG.Error("query参数错误")
			response.FailWithMessage("参数错误", c)
		}
		global.GVA_LOG.Info("query请求参数", zap.Any("query", req))
		total, list, err := service.InPositionUserList(req)
		if err != nil {
			global.GVA_LOG.Error("获取出勤员工表错误", zap.Error(err))
			response.FailWithMessage("内部错误", c)
			return
		}
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     req.Page,
			PageSize: req.PageSize,
		}, "获取成功", c)
	case global.DATA_STATISTICS_ATTENDANCE:
		result, err := service.AttendanceOverview()
		if err != nil {
			global.GVA_LOG.Error("获取出勤表错误", zap.Error(err))
			response.FailWithMessage("内部错误", c)
			return
		}
		response.OkWithDetailed(result, "查询成功", c)
	case global.DATA_STATISTICS_MANAGEMENT_INPOSITION:
		result, err := service.ManageInPosition()
		if err != nil {
			global.GVA_LOG.Error("获取中高层到岗表错误", zap.Error(err))
			response.FailWithMessage("内部错误", c)
			return
		}
		response.OkWithDetailed(result, "查询成功", c)
	case global.DATA_STATISTICS_MANAGEMENT_HOME:
		result, err := service.ManageHome()
		if err != nil {
			global.GVA_LOG.Error("获取中高层居家表错误", zap.Error(err))
			response.FailWithMessage("内部错误", c)
			return
		}
		response.OkWithDetailed(result, "查询成功", c)
	default:
		global.GVA_LOG.Error("参数错误")
		response.FailWithMessage("参数错误", c)
	}
}
